{# shared block for listing templates + categories in 'create-new-item-...-modal.html' #}
{# expects: entityPage, templatesArr, itemsTemplatesArr, (optional) categoryArr #}
{# optional overrides: actionName, templatesPageOverride, categoryPageOverride, alwaysShowCategories #}
<div id='tplCreateNewDiv_{{ entityPage }}' class='vertically-limited'>
  {% if templatesArr|length == 0 %}
    {{ 'No templates found.'|trans }}
  {% else %}
    <input type='text' aria-label='{{ 'Filter'|trans }}' placeholder='{{ 'Filter'|trans }}' data-filter-target='tplCreateNewTable_{{ entityPage }}' data-target-type='tr' class='form-control form-inline'>
    <table class='table' aria-describedby='createModalLabel_{{ entityPage }}' data-table-sort='true'>
      <thead>
      <tr>
        <th scope='col'>{{ 'Title'|trans }}</th>
        <th scope='col'>{{ 'Owner'|trans }}</th>
      </tr>
      </thead>
      <tbody id='tplCreateNewTable_{{ entityPage }}'>
      {% set label = entityPage == 'database' ? 'Create resource from template'|trans : 'Create experiment from template'|trans %}
      {% for template in templatesArr %}
        <tr>
          <td data-label='{{ 'Title'|trans }}'>
            <a data-action='{{ actionName|default('create-entity') }}' data-type='{{ entityPage }}' data-tplid='{{ template.id }}' href='#' class='p-2 rounded mr-2 hl-hover-gray' title='{{ label }}' aria-label='{{ label }}'>
              <i class='fas fa-file-circle-plus fa-fw color-blue'></i>
            </a>
            <a href='{{ Entity.entityType.toTemplatePage() }}?mode=view&id={{ template.id }}' class='p-2 rounded mr-2 hl-hover-gray' title='{{ 'View template'|trans }}' aria-label='{{ 'View template'|trans }}'>
              <i class='fas fa-eye fa-fw'></i>
            </a>
            {% if template.category_title %}
              <span class='catstat-btn category-btn mr-2' style='--bg: #{{ template.category_color|default('bdbdbd') }}'>{{ template.category_title }}</span>
            {% endif %}
            {% if template.status %}
              <span class='catstat-btn status-btn mr-2' style='--bg: #{{ template.status_color|default('bdbdbd') }}'>{{ template.status_title }}</span>
            {% endif %}
            {{ template.title }}
          </td>
          <td data-label='{{ 'Owner'|trans }}'>{{ template.fullname }}</td>
        </tr>
      {% endfor %}
      </tbody>
    </table>
  {% endif %}
</div>
{% if alwaysShowCategories or (not App.Teams.teamArr.force_exp_tpl) %}
  <hr>
  <div class='d-flex flex-row justify-content-between mb-2'>
    <h5 class='modal-title'>{{ 'Or select a category'|trans }}</h5>
    {% set categoryPage = categoryPageOverride|default(Entity.entityType.toCategoryPage()|default(entityPage == 'database' ? 'resources-categories.php' : 'experiments-categories.php')) %}
    <a href='{{ categoryPage }}' class='btn btn-ghost btn-sm'><i class='fas fa-cogs mr-1'></i>{{ 'Manage categories'|trans }}</a>
  </div>
  {# if we're creating item from compounds page or chem-editor page, use 'create-resource-from-compound' action. #}
  {% set action = (scriptName == 'compounds.php' or scriptName == 'chem-editor.php') ? actionName : 'create-entity-ask-title' %}
  <a class='btn btn-ghost mt-1' href='#' data-action='{{ action }}' data-type='{{ entityPage }}' data-catid='-1'>
    <span class='round-spot round-spot-ghost mr-1'></span>{{ 'No category'|trans }}
  </a>
  {% set categoryArr = entityPage == 'experiments' ? App.experimentsCategoryArr : App.itemsCategoryArr %}
  {% for category in categoryArr %}
    <a class='btn btn-ghost mt-1' href='#' data-action='{{ action }}' data-type='{{ entityPage }}' data-catid='{{ category.id }}'>
      <span class='round-spot mr-1' style='background-color: #{{ category.color }};'></span>{{ category.title }}
    </a>
  {% endfor %}
{% endif %}
